import 'package:baselib/util/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app/controller/ForgetPassControl.dart';
import 'package:flutter_app/util/colours.dart';
import 'package:get/get.dart';
class forgetPassDialog extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new forgetPassDialogState();
  }

}

class forgetPassDialogState extends State<forgetPassDialog>{

  ///账号的控制器
  TextEditingController userphoneController = TextEditingController();
  TextEditingController usercodeController = TextEditingController();
  TextEditingController userNewPassController = TextEditingController();
  TextEditingController userAgainPassController = TextEditingController();
  final ForgetPassController control = Get.put(ForgetPassController());
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          _buildBar(context),
          Container(
            alignment: Alignment.topCenter,
            child: Image.asset(
              CommonUtils.getImgPath("logo.png"),
              height: 50,
            ),
          ),
          buildTextFiled()
        ],
      ),
    );
  }

  ///输入框
  Widget buildTextFiled(){
    return Column(
      children: [
        SizedBox(height: 10,),
        buildPhone(),
        SizedBox(height: 10,),
        buildCode(),
        SizedBox(height: 10,),
        buildNewPass(),
        SizedBox(height: 10,),
        buildOldPass(),
        SizedBox(height: 10,),
        buildLoginBtn()
      ],
    );
  }

  ///手机号
  Widget buildPhone(){
    return  Container(
      width: 300,
      child: TextField(
        controller: userphoneController,
        autocorrect: true,
        //是否自动更正
        inputFormatters: [FilteringTextInputFormatter.digitsOnly],
        //允许的输入格式
        style: new TextStyle(
            color: Colors.black, fontSize: 15),
        decoration: InputDecoration(
          hintText: "请输入手机号",
          hintStyle: new TextStyle(
              color: ColourRes.app_A8A7A5,
              fontSize: 15),
          border:OutlineInputBorder(borderRadius:BorderRadius.circular(4),
              borderSide: BorderSide(color: Colors.grey,)),
          // errorText:control.userPhoneErrortext.value,

        ),
        onChanged: (str) {
          control.userPhone.value = str;
          // if(str.isNotEmpty) {
          //   control.userPhoneErrortext.value= null;
          // }else{
          //   control.userPhoneErrortext.value = "手机号不能为空";
          // }
        },
      ),
    );
  }

  ///验证码
  Widget buildCode(){
    return  Container(
      width: 300,
      padding: EdgeInsets.only(left: 10),
      decoration:BoxDecoration(
        shape: BoxShape.rectangle,
        borderRadius: BorderRadius.circular(4),
        border: Border.all(color: Colors.grey)
      ),
      child: Row(
        children: [
          Container(
            width: 150,
            child: TextField(
              controller: usercodeController,
              autocorrect: true,
              //是否自动更正
              inputFormatters: [FilteringTextInputFormatter.digitsOnly],
              //允许的输入格式
              style: new TextStyle(
                  color: Colors.black, fontSize: 15),
              decoration: InputDecoration(
                hintText: "请输入验证码",
                hintStyle: new TextStyle(
                    color: ColourRes.app_A8A7A5,
                    fontSize: 15),
                border:InputBorder.none,
                // errorText:control.userPhoneErrortext.value,
              ),
              onChanged: (str) {
                control.userCode.value = str;
              },
            ),
          ),
          Spacer(),
          Expanded(child:
          GestureDetector(
            onTap:(){
              if(control.start.value==120) {
                control.getSmsCode(context);
              }
            },
            child: Obx(()=>Text(control.start.value == 120 ? "获取验证码" : "${control.start.value}s",
                style: new TextStyle(
                    color: control.start.value == 120 ? ColourRes
                        .app_6E7C8C : Color(0xffF2502C),
                    fontSize: 12))),
          )
          ),
        ],
      ),
    );
  }

  ///新密码
  Widget buildNewPass(){
    return  Container(
      width: 300,
      child: TextField(
        controller: userNewPassController,
        autocorrect: true,
        obscureText: true,
        //是否自动更正
        //允许的输入格式
        style: new TextStyle(
            color: Colors.black, fontSize: 15),
        decoration: InputDecoration(
          hintText: "请输入新密码",
          hintStyle: new TextStyle(
              color: ColourRes.app_A8A7A5,
              fontSize: 15),
          border:OutlineInputBorder(borderRadius:BorderRadius.circular(4),
              borderSide: BorderSide(color: Colors.grey,)),
          // errorText:control.userPhoneErrortext.value,

        ),
        onChanged: (str) {
          control.userNewPass.value = str;
          // if(str.isNotEmpty) {
          //   control.userPhoneErrortext.value= null;
          // }else{
          //   control.userPhoneErrortext.value = "手机号不能为空";
          // }
        },
      ),
    );
  }

  ///旧密码
  Widget buildOldPass(){
    return  Container(
      width: 300,
      child: TextField(
        controller: userAgainPassController,
        autocorrect: true,
        obscureText: true,
        //是否自动更正
        //允许的输入格式
        style: new TextStyle(
            color: Colors.black, fontSize: 15),
        decoration: InputDecoration(
          hintText: "请再次输入密码",
          hintStyle: new TextStyle(
              color: ColourRes.app_A8A7A5,
              fontSize: 15),
          border:OutlineInputBorder(borderRadius:BorderRadius.circular(4),
              borderSide: BorderSide(color: Colors.grey,)),
          // errorText:control.userPhoneErrortext.value,

        ),
        onChanged: (str) {
          control.userAgainPass.value = str;
          // if(str.isNotEmpty) {
          //   control.userPhoneErrortext.value= null;
          // }else{
          //   control.userPhoneErrortext.value = "手机号不能为空";
          // }
        },
      ),
    );
  }


  ///修改按钮
  Widget buildLoginBtn() {
    return Center(
      child: Container(
        width: 300,
        height: 50,
        child: TextButton(
          child: Text("确定修改",
              style: new TextStyle(
                  color: ColourRes.app_1A4677, fontSize: 18)),
          style: ButtonStyle(
              backgroundColor:MaterialStateProperty.all(Color(0xffF1F8FF)),
              shape: MaterialStateProperty.all(RoundedRectangleBorder(
                  side: BorderSide(color: ColourRes.app_1A4677),
                  borderRadius: BorderRadius.all(
                      Radius.circular(4))))
          ),
          onPressed: () {
            control.updatePass(context);
          },
        ),
      ),
    );
  }

  ///关闭按钮
  _buildBar(context) =>
      Container(
        height: 30,
        alignment: Alignment.centerRight,
        margin: EdgeInsets.only(right: 10, top: 5),
        child: InkWell(
          onTap: () => Navigator.pop(context),
          child: Icon(
            Icons.close,
            color: Color(0xffD8D8D8),
          ),
        ),
      );
}